//
//  CYInvestRecordCell.m
//  cyjf
//
//  Created by tauCross on 2017/5/19.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYInvestRecordCell.h"



@implementation CYInvestRecordCellObject

@end



@interface CYInvestRecordCell ()

@property(nonatomic, strong)UIImageView *titleLine;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UILabel *dueDayLabel;
@property(nonatomic, strong)UIImageView *topLine;
@property(nonatomic, strong)UIImageView *contentLine;
@property(nonatomic, strong)UILabel *capitalDescLabel;
@property(nonatomic, strong)UILabel *profitsDescLabel;
@property(nonatomic, strong)UILabel *capitalLabel;
@property(nonatomic, strong)UILabel *profitsLabel;
@property(nonatomic, strong)UILabel *investDateLabel;
@property(nonatomic, strong)UILabel *dueDateLabel;

@end


@implementation CYInvestRecordCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor clearColor];
        
        self.titleLine = [UIImageView cy_imageLineWithColor:HEXCOLOR(@"444444")];
        self.titleLine.width = 2;
        self.titleLine.height = 10;
        [self.contentView addSubview:self.titleLine];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textColor = HEXCOLOR(@"444444");
        self.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.titleLabel];
        
        self.dueDayLabel = [[UILabel alloc] init];
        self.dueDayLabel.textColor = HEXCOLOR(@"444444");
        self.dueDayLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.dueDayLabel];
        
        self.topLine = [UIImageView cy_imageLineWithColor:HEXCOLOR(@"ECECEC")];
        [self.contentView addSubview:self.topLine];
        
        self.contentLine = [UIImageView cy_imageLineWithColor:HEXCOLOR(@"ECECEC")];
        [self.contentView addSubview:self.contentLine];
        
        self.capitalDescLabel = [[UILabel alloc] init];
        self.capitalDescLabel.text = @"投资本金";
        self.capitalDescLabel.font = [UIFont systemFontOfSize:12];
        self.capitalDescLabel.textColor = HEXCOLOR(@"999999");
        [self.capitalDescLabel sizeToFit];
        [self.contentView addSubview:self.capitalDescLabel];
        
        self.profitsDescLabel = [[UILabel alloc] init];
        self.profitsDescLabel.font = [UIFont systemFontOfSize:12];
        self.profitsDescLabel.textColor = HEXCOLOR(@"999999");
        [self.contentView addSubview:self.profitsDescLabel];
        
        self.capitalLabel = [[UILabel alloc] init];
        self.capitalLabel.font = [UIFont systemFontOfSize:18];
        self.capitalLabel.textColor = APP_DEFAULT_COLOR_RED;
        [self.contentView addSubview:self.capitalLabel];
        
        self.profitsLabel = [[UILabel alloc] init];
        self.profitsLabel.font = [UIFont systemFontOfSize:18];
        self.profitsLabel.textColor = APP_DEFAULT_COLOR_RED;
        [self.contentView addSubview:self.profitsLabel];
        
        self.investDateLabel = [[UILabel alloc] init];
        self.investDateLabel.font = [UIFont systemFontOfSize:14];
        self.investDateLabel.textColor = HEXCOLOR(@"666666");
        [self.contentView addSubview:self.investDateLabel];
        
        self.dueDateLabel = [[UILabel alloc] init];
        self.dueDateLabel.font = [UIFont systemFontOfSize:14];
        self.dueDateLabel.textColor = HEXCOLOR(@"666666");
        [self.contentView addSubview:self.dueDateLabel];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 160;
}

- (BOOL)shouldUpdateCellWithObject:(CYInvestRecordCellObject *)object
{
    self.titleLabel.text = object.title;
    
    self.dueDayLabel.hidden = object.dueDay == nil;
    self.dueDayLabel.text = [NSString stringWithFormat:@"%@天后到期", object.dueDay];
    
    self.profitsDescLabel.text = object.dueDay != nil ? @"待收利息" : @"已收利息";
    
    self.capitalLabel.text = [NSString stringWithFormat:@"%@元", object.capital.amountString];
    
    self.profitsLabel.text = [NSString stringWithFormat:@"%@元", object.profits.amountString];
    
    self.investDateLabel.text = [NSString stringWithFormat:@"投资时间:%@", object.investDate];
    
    self.dueDateLabel.text = [NSString stringWithFormat:@"到期时间:%@", object.dueDate];
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.contentView.width = self.width;
    self.contentView.height = self.height - 10;
    self.contentView.left = 0;
    self.contentView.centerY = self.height / 2;
    
    self.selectedBackgroundView.frame = self.contentView.frame;
    
    self.titleLine.left = 20;
    self.titleLine.centerY = 22;
    
    [self.titleLabel sizeToFit];
    self.titleLabel.centerY = 22;
    self.titleLabel.left = 28;
    
    [self.dueDayLabel sizeToFit];
    self.dueDayLabel.centerY = 22;
    self.dueDayLabel.right = self.contentView.width - 20;
    
    self.topLine.width = self.contentView.width - 40;
    self.topLine.height = 1 / SCREEN_SCALE;
    self.topLine.bottom = 44;
    self.topLine.centerX = self.contentView.width / 2;
    
    self.contentLine.width = 1 / SCREEN_SCALE;
    self.contentLine.height = 30;
    self.contentLine.centerY = 86;
    self.contentLine.centerX = self.contentView.width / 2;
    
    self.capitalDescLabel.right = self.contentView.width / 2 - 10;
    self.capitalDescLabel.centerY = 73;
    
    [self.profitsDescLabel sizeToFit];
    self.profitsDescLabel.left = self.contentView.width / 2 + 10;
    self.profitsDescLabel.centerY = 73;
    
    [self.capitalLabel sizeToFit];
    self.capitalLabel.right = self.contentView.width / 2 - 10;
    self.capitalLabel.centerY = 93;
    
    [self.profitsLabel sizeToFit];
    self.profitsLabel.left = self.contentView.width / 2 + 10;
    self.profitsLabel.centerY = 93;
    
    [self.investDateLabel sizeToFit];
    self.investDateLabel.right = self.contentView.width / 2 - 10;
    self.investDateLabel.centerY = 128;
    
    [self.dueDateLabel sizeToFit];
    self.dueDateLabel.left = self.contentView.width / 2 + 10;
    self.dueDateLabel.centerY = 128;
}

@end
